package com.camps.sdk.encrypt;

import com.camps.sdk.common.ExceptionCode;
import com.camps.sdk.entity.NoDisturb;
import com.camps.sdk.exception.BaseException;
import com.camps.sdk.utils.RepeatTimeUtils;

/**
 * @Author ldaoliang
 * @Date create in 10:11 2021/9/1
 * @Description
 */
public class NoDisturbCommand implements BuildCommand {
    @Override
    public String splicingParameters(String imei, Object params) {
        if(!(params instanceof NoDisturb)){
            throw new BaseException(ExceptionCode.PARAMETER_ERROR);
        }
        NoDisturb noDisturb = (NoDisturb)params;
        String commandNumber = noDisturb.getCommandNumber();
        Integer sequence = noDisturb.getSequence();
        String beginTime = noDisturb.getBeginTime();
        String endTime = noDisturb.getEndTime();
        String repeatTime = noDisturb.getRepeatTime();
        // 构建repeatTime数据
        try{
            repeatTime = RepeatTimeUtils.sendEncode(repeatTime);
        }catch (Exception e){
            throw new BaseException(ExceptionCode.REPEAT_TIME_ERROR);
        }
        StringBuilder sb = new StringBuilder("*WT,");
        sb.append(imei).append(",CLASS").append(commandNumber).append(",").append(sequence)
                .append(beginTime.replaceAll(":",""))
                .append(endTime.replaceAll(":",""))
                .append(repeatTime).append("#");
        return sb.toString();
    }
}
